

#include <sys/cdefs.h>
#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <assert.h>
#include <string.h>
#else
#include <lib/libkern/libkern.h>
#endif

void *
memchr(const void *s, int c, size_t n)
{
	_DIAGASSERT(s != NULL);

	if (n != 0) {
		const unsigned char *p = s;
		const unsigned char cmp = c;

		do {
			if (*p++ == cmp)
				return __UNCONST(p - 1);
		} while (--n != 0);
	}
	return NULL;
}
